package com.ticket.sass.admin.dto.input;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import java.lang.reflect.Field;
import java.time.LocalDate;
import java.util.List;

/**
 * @author ywb
 * @date 2022-09-23 15:07
 */
@Data
@ToString
@ApiModel("页数输入")
public class PageInput {
    @ApiModelProperty(value = "页数")
    @Min(value = 1, message = "页数必须大于等于1")
    private Integer pageNum = 1;

    @ApiModelProperty("每页大小 最大 200 默认 10")
    @Range(max = 200, min = 1, message = "页数大小范围应该在1-200内。")
    private Integer pageSize = 10;
    
    /**
     * 检查是否有筛选条件
     * @return true 如果有筛选条件，否则 false
     */
    public boolean hasFilter() {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                Object value = field.get(this);
                if (value instanceof String && !((String) value).trim().isEmpty()) {
                    return true;
                } else if (value instanceof Number && ((Number) value).doubleValue() != 0) {
                    return true;
                } else if (value instanceof LocalDate && value != null) {
                    return true;
                } else if (value instanceof List && value != null && !((List<?>) value).isEmpty()) {
                    return true;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}